package com.shujia.transformation

import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.time.Time

object Demo07Window {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    // 通过socket构建无界流
    val socketDS: DataStream[String] = env.socketTextStream("master", 8888)

    socketDS
      .flatMap(_.split(","))
      .map(word => (word, 1))
      .keyBy(_._1)
      // 每5s中统计一次 相当于滚动窗口
      //      .timeWindow(Time.seconds(5))
      // 每隔5s统计最近10s内的数据 相当于滑动窗口
      .timeWindow(Time.seconds(10), Time.seconds(5))
      .sum(1)
      .print()


    env.execute()


  }

}
